import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';

import '../index.dart';

class ExpansionItem extends GetView<LiveRecordController> {
  final String item;

  const ExpansionItem({
    Key? key,
    required this.item,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ExpansionTile(
      key: ValueKey(item),
      title: _buildTile(),
      tilePadding: const EdgeInsets.symmetric(horizontal: 15),
      iconColor: AppColors.active,
      collapsedIconColor: AppColors.unactive,
      backgroundColor: Colors.white,
      shape: const Border.fromBorderSide(BorderSide.none),
      childrenPadding: const EdgeInsets.symmetric(
        vertical: 0,
        horizontal: 15,
      ),
      children: _buildContent(),
    );
  }

  /// 折叠头部
  Widget _buildTile() {
    return const Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        Text(
          '2023-12-16 18:00',
          style: TextStyle(
            fontSize: 12,
            color: Color(0xFF641013),
          ),
        ),
        Text(
          '1小时30分钟',
          style: TextStyle(
            fontSize: 12,
            color: AppColors.unactive,
          ),
        ),
        Text(
          '2000人',
          style: TextStyle(
            fontSize: 12,
            color: AppColors.unactive,
          ),
        ),
        Text(
          '200读币',
          style: TextStyle(
            fontSize: 12,
            fontWeight: FontWeight.w500,
            color: Color(0xFFCBA43F),
          ),
        ),
      ],
    );
  }

  /// 折叠内容
  List<Widget> _buildContent() {
    return [
      _buildContentItem(label: '累计观看：', value: '3888人'),
      _buildContentItem(label: '最高在线：', value: '3888人'),
      _buildContentItem(label: '平均在线：', value: '3888人'),
      _buildContentItem(label: '互动评论：', value: '88条'),
      _buildContentItem(label: '读币收入：', value: '3888'),
      _buildContentItem(label: '直播时长：', value: '1小时30分钟32秒'),
    ];
  }

  /// 折叠内容每一项
  Widget _buildContentItem({
    required String label,
    required String value,
  }) {
    return Column(
      children: [
        _buildDivider(),
        SizedBox(
          height: 44,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                label,
                style: const TextStyle(
                  fontSize: 12,
                  color: AppColors.unactive,
                ),
              ),
              Text(
                value,
                style: const TextStyle(
                  fontSize: 12,
                  color: AppColors.unactive,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  /// 分割线
  Widget _buildDivider() {
    return const Divider(
      height: 0,
      indent: 0,
      endIndent: 0,
      thickness: 0.5,
      color: AppColors.border,
    );
  }
}
